<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.stms.action.Stms9003ActionBean"%>
<%@page import="com.feib.stms.pagination.PaginatedList"%>
<%@page import="com.feib.stms.util.UserUtil"%>
<%
// 欄位排序處理
Stms9003ActionBean actionBean = (Stms9003ActionBean) request.getAttribute("actionBean");
if (null != actionBean && null != actionBean.getQueryResult())
{
	PaginatedList queryResult = actionBean.getQueryResult();
	int sortDirection = queryResult.getSortDirection();  //2 : ascending, else: descending
	String sortSpan = "<span class=\"ui-icon ui-icon-circle-triangle-n\"></span>"; //由小到大
	if (1 == sortDirection)
	{
		sortSpan = "<span class=\"ui-icon ui-icon-circle-triangle-s\"></span>"; //由大到小
	}
	
	String sortCriterion = queryResult.getSortCriterion();
	if (null != sortCriterion && 0 != sortCriterion.length())
	{
		if ("uploadDate".equalsIgnoreCase(sortCriterion))
		{
			pageContext.setAttribute("uploadDateSortedClass", 1==sortDirection?"sortDesc":"sortAsc");
			pageContext.setAttribute("uploadDateSortedSpan", sortSpan);
		}
		else if ("fileFormat".equalsIgnoreCase(sortCriterion))
		{
			pageContext.setAttribute("fileFormatSortedClass", 1==sortDirection?"sortDesc":"sortAsc");
			pageContext.setAttribute("fileFormatSortedSpan", sortSpan);
		}
		else if ("fileName".equalsIgnoreCase(sortCriterion))
		{
			pageContext.setAttribute("fileNameSortedClass", 1==sortDirection?"sortDesc":"sortAsc");
			pageContext.setAttribute("fileNameSortedSpan", sortSpan);
		}
		else if ("uploadUser".equalsIgnoreCase(sortCriterion))
		{
			pageContext.setAttribute("uploadUserSortedClass", 1==sortDirection?"sortDesc":"sortAsc");
			pageContext.setAttribute("uploadUserSortedSpan", sortSpan);
		}
	}
	
	// 上下頁鈕處理
	int lastPageNumber = queryResult.getTotalPageCount();
	int currentPageNumber = queryResult.getPageNumber();
	int prePageNumber = currentPageNumber - 1;
	int nextPageNumber = currentPageNumber + 1;
	
	pageContext.setAttribute("lastPageNumber", new Integer(lastPageNumber));
	pageContext.setAttribute("currentPageNumber", new Integer(currentPageNumber));
	pageContext.setAttribute("prePageNumber", new Integer(prePageNumber));
	pageContext.setAttribute("nextPageNumber", new Integer(nextPageNumber));
} // end of if (null != actionBean && null != actionBean.getQueryResult())

%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
            
    <script type="text/javascript">
    <!-- 
    $(document).ready(function() {
    
    
     	$('#findGroupNoDiv').click(function() {
    		var url = '<c:url value="/Group.action"/>?qryGroup.groupNo=' + $('#qryUploadFile\\.group\\.groupNo').val();
    		var varOptions = 'help:no;status:no;scroll:yes;resize:yes;center:yes;dialogHeight:700px;dialogWidth:900px';
    		var dialogArguments = new Object();
    		dialogArguments.parentWindowObj = self;
    		dialogArguments.groupNoId = 'qryUploadFile.group.groupNo';
    		dialogArguments.groupPkId = 'qryUploadFile.group.groupPk';
    		dialogArguments.groupNameId = 'qryFormatDefinition.group.groupName.span';
    		dialogArguments.checkboxDiv = 'securitiesCheckBoxDiv';
    		
    		var s = showModalDialog(url, dialogArguments, varOptions);

    		return true;				
		}); 
    
    	$('#doQueryBtn').click(function() {
    		var qryUploaddDateFrom = $('#qryUploaddDateFrom').val();
    		var qryUploadDateHourFrom = $('#qryUploadDateHourFrom').val();
    		var qryUploadDateTo = $('#qryUploadDateTo').val();
    		var qryUploadDateHourTo = $('#qryUploadDateHourTo').val();
    		var qryUploadUserId = $('#qryUploadUserId').val();
    		var errorMessage = '';
    		if (qryUploaddDateFrom == '') errorMessage = '上傳日期(起)不可空白!!';
    		if (qryUploadDateTo == '')
    		{
    		    if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    errorMessage = errorMessage + '上傳日期(迄)不可空白!!';
    		}
    		
    		var isDoConfirm = false;
    		$('#queryUploadFileFrom input:checkbox').each(function(){
    			if ( $(this).attr('checked') ){
    				isDoConfirm = true;
                }
            });
            
            if (isDoConfirm == false)
    		{
    		    if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    errorMessage = errorMessage + '至少選擇一種上傳類別!!';
    		} 
            
            if (errorMessage != '')
            {
                showErrorMessageDialog(errorMessage);
                return false;
            }
            
    		return true;
				
		});
		  		 //全選 
      $('#checkboxAll').click(function() 
        {
         var chk = $('#checkboxAll').attr('checked');   			
         $('#queryForm input:checkbox').each(function(){  
         
         if("checked"==chk){ 
    		 $(this).attr('checked', chk);
    		}  				
    	else{
			 $(this).removeAttr('checked');
    		}
           });
        });  
		
		$('#qryUploadFile\\.group\\.groupNo').change(function() {
 			$('#qryUploadFile\\.group\\.groupPk').val('');
 			$('#qryFormatDefinition\\.group\\.groupName\\.span').text('');
 			$('#securitiesCheckBoxDiv').html('');
		});
		
<c:if test="${null != actionBean.queryResult && not empty actionBean.queryResult.paginatedList}">
		
		$("[id^='viewDetail-']").click(function() {
			var uploadFilePk = this.id.substring(11);
			var groupNo = $('#qryUploadFile\\.group\\.groupNo').val();
    		var groupPk = $('#qryUploadFile\\.group\\.groupPk').val();
  
    		$('#hidden\\.qryUploadFile\\.group\\.groupNo').val(groupNo);
    		$('#hidden\\.qryUploadFile\\.group\\.groupPk').val(groupPk);
			$('#hidden\\.qryUploadFilePk').val(uploadFilePk);
			$("#hidden\\.doViewDetailBtn").trigger('click');
		});
		
		$("[id^='a-sortHeader-']").click(function() {
			var sortField = this.id.substring(13);
			$('#hidden\\.queryResult\\.sortCriterion').val(sortField);
			
			var clazz = $(this).attr('class');
		
			if (null == clazz || 0 == clazz.length)
				$('#hidden\\.queryResult\\.sortDirection').val('1');
			else if ('sortAsc' == clazz)
				$('#hidden\\.queryResult\\.sortDirection').val('1');
			else
				$('#hidden\\.queryResult\\.sortDirection').val('2');
				
			$('#hidden\\.queryResult\\.pageNumber').val('1');
				 
			$("#hidden\\.doQueryBtn").trigger('click');
			
			return false;
		});
		
		$("[id^='firstPageBtn']").click(function() {
			$('#hidden\\.queryResult\\.pageNumber').val('1');
			$("#hidden\\.doQueryBtn").trigger('click');
		});
		
		$("[id^='prePageBtn']").click(function() {
			$('#hidden\\.queryResult\\.pageNumber').val('<c:out value="${prePageNumber}"/>');
			$("#hidden\\.doQueryBtn").trigger('click');
		});
		
		$("[id^='nextPageBtn']").click(function() {
			$('#hidden\\.queryResult\\.pageNumber').val('<c:out value="${nextPageNumber}"/>');
			$("#hidden\\.doQueryBtn").trigger('click');
		});
		
		$("[id^='lastPageBtn']").click(function() {
			$('#hidden\\.queryResult\\.pageNumber').val('<c:out value="${lastPageNumber}"/>');
			$("#hidden\\.doQueryBtn").trigger('click');
		});
		
		$("[id^='currentPageText']").change(function() {
			var value = this.value;
			if (value != ''){
				value = value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
				var intRegex = /^\d+$/;
				if(!intRegex.test(value)) {
					showErrorMessageDialog('頁數必須是整數');
					return ;
				}
				
				value = parseInt(value, 10);
				
				if (value < 1){
					showErrorMessageDialog('頁數必須是大於1');
					return ;
				}
				else if (value > <c:out value='${lastPageNumber}'/>){
					showErrorMessageDialog('頁數必須是小於總頁數 (<c:out value="${lastPageNumber}"/>)');
					return ;
				}
				else if (value != <c:out value='${currentPageNumber}'/>){
					$('#hidden\\.queryResult\\.pageNumber').val(value);
					$("#hidden\\.doQueryBtn").trigger('click');
					return false;
				}
				
			}
			else{
				showErrorMessageDialog('頁數不可為空白)');
				return ;
			}
		});
		
		
	
		
		
		
		
</c:if>
		
		<c:if test="${not empty actionBean.message}">
    	showMessageDialog('<c:out value="${actionBean.message }" escapeXml="false"/>');
    	</c:if>
		
		<c:if test="${not empty actionBean.errorMessage}">
    	showErrorMessageDialog('<c:out value="${actionBean.errorMessage }" escapeXml="false"/>');
    	</c:if>
    	
    	var dates = $( "#qryUploaddDateFrom, #qryUploadDateTo" ).datepicker({
			defaultDate: "-1m",
			changeMonth: true,
			changeYear: true,
			numberOfMonths: 1,
			dateFormat: 'yy/mm/dd',
			showButtonPanel: true,
			showOn: "both",
			buttonImage: "<c:url value='styles/default/image/calendar.gif'/>",
			buttonImageOnly: true,
			onSelect: function( selectedDate ) {
				var option = this.id == "qryUploaddDateFrom" ? "minDate" : "maxDate",
					instance = $( this ).data( "datepicker" );
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
				dates.not( this ).datepicker( "option", option, date );
			}
		});
                  
    });
    
    function doPrintEvent()
    {
    	divPrint('listForm');
    	return false;
    }
    
    //-->
    </script>
</head>
<body>
	
	<div id="smallQueryForm"></div>

<stripes:form id="queryUploadFileFrom" beanclass="com.feib.stms.action.Stms9003ActionBean" method="post" onsubmit="javascript: waitingDialog({});">

	<div id="queryForm">
		<table>
			<tr>
				<td colspan="5" class="queryHeader">請輸入查詢條件</td>
			</tr>
				<%if ( UserUtil.isBankGroup()){ %>
			<tr>
				<th>券商代號<span id="mustKeyInStar">**</span></th>
				<td>
					<div id="findGroupNoDiv" class="widgetsIcon ui-state-default ui-corner-all" title="查詢券商"><span class="ui-icon ui-icon-zoomin"></span></div>
					<stripes:text id="qryUploadFile.group.groupNo" name="qryUploadFile.group.groupNo" size="12" maxlength="12" />
					<span id="qryFormatDefinition.group.groupName.span"><c:out value="${actionBean.qryUploadFile.group.groupName }"/></span>	
					<stripes:hidden id="qryUploadFile.group.groupPk" name="qryUploadFile.group.groupPk" />			
				</td>
			</tr>
			<%} else {%>
			<stripes:hidden id="qryUploadFile.group.groupNo" name="qryUploadFile.group.groupNo" />
			<stripes:hidden id="qryUploadFile.group.groupPk" name="qryUploadFile.group.groupPk" />
			<%} %>
			<tr>
				<th>上傳日期<span id="mustKeyInStar">**</span></th>
				<td colspan="4">
				<stripes:text id="qryUploaddDateFrom" name="qryUploaddDateFrom" size="10" maxlength="10" formatPattern="yyyy/MM/dd" readonly="true"/>
				<stripes:select id="qryUploadDateHourFrom" name="qryUploadDateHourFrom">
					<stripes:option value="0" label="00"/>
					<stripes:option value="1" label="01"/>
					<stripes:option value="2" label="02"/>
					<stripes:option value="3" label="03"/>
					<stripes:option value="4" label="04"/>
					<stripes:option value="5" label="05"/>
					<stripes:option value="6" label="06"/>
					<stripes:option value="7" label="07"/>
					<stripes:option value="8" label="08"/>
					<stripes:option value="9" label="09"/>
					<stripes:option value="10" label="10"/>
					<stripes:option value="11" label="11"/>
					<stripes:option value="12" label="12"/>
					<stripes:option value="13" label="13"/>
					<stripes:option value="14" label="14"/>
					<stripes:option value="15" label="15"/>
					<stripes:option value="16" label="16"/>
					<stripes:option value="17" label="17"/>
					<stripes:option value="18" label="18"/>
					<stripes:option value="19" label="19"/>
					<stripes:option value="20" label="20"/>
					<stripes:option value="21" label="21"/>
					<stripes:option value="22" label="22"/>
					<stripes:option value="23" label="23"/>						
					<stripes:option value="24" label="24"/>
				</stripes:select>
					～
				<stripes:text id="qryUploadDateTo" name="qryUploadDateTo" size="10" maxlength="10" formatPattern="yyyy/MM/dd" readonly="true"/>
				<stripes:select id="qryUploadDateHourTo" name="qryUploadDateHourTo">
					<stripes:option value="0" label="00"/>
					<stripes:option value="1" label="01"/>
					<stripes:option value="2" label="02"/>
					<stripes:option value="3" label="03"/>
					<stripes:option value="4" label="04"/>
					<stripes:option value="5" label="05"/>
					<stripes:option value="6" label="06"/>
					<stripes:option value="7" label="07"/>
					<stripes:option value="8" label="08"/>
					<stripes:option value="9" label="09"/>
					<stripes:option value="10" label="10"/>
					<stripes:option value="11" label="11"/>
					<stripes:option value="12" label="12"/>
					<stripes:option value="13" label="13"/>
					<stripes:option value="14" label="14"/>
					<stripes:option value="15" label="15"/>
					<stripes:option value="16" label="16"/>
					<stripes:option value="17" label="17"/>
					<stripes:option value="18" label="18"/>
					<stripes:option value="19" label="19"/>
					<stripes:option value="20" label="20"/>
					<stripes:option value="21" label="21"/>
					<stripes:option value="22" label="22"/>
					<stripes:option value="23" label="23"/>						
					<stripes:option value="24" label="24"/>
				</stripes:select>
				</td>
			</tr>
			<tr>
				<th>上傳經辦ID</th>
				<td colspan="4"><stripes:text id="qryUploadUserId" name="qryUploadUserId" size="10" maxlength="10" /></td>
			</tr>
			<tr>
				<th>上傳類別<span id="mustKeyInStar">**</span></th>
				<td colspan="4">
				<input type="checkbox" name="checkboxAll" id="checkboxAll" value="全選"/>全選&nbsp;
					<c:forEach items="${actionBean.uploadFileFormats}" var="uploadFileFormatObj" varStatus="rowstat">
						<stripes:checkbox id="qryFileFormats[${rowstat.index}]" name="qryFileFormats[${rowstat.index}]" value="${uploadFileFormatObj.value}"/> <c:out value="${uploadFileFormatObj.label}" />&nbsp;
					</c:forEach>
					
				</td>
			</tr>
			<tr>
				<td colspan="5" class="queryFunction"><stripes:submit id="doQueryBtn" name="doQuery" value="查詢" class="formBtn"/></td>
			</tr>
		</table>
	</div>
</stripes:form>	

	
	<div id="listForm">
	
<c:if test="${null != actionBean.queryResult && not empty actionBean.queryResult.paginatedList}">
		
		<div id="paginationBar" style=" margin: 0 auto;">
			<input type="button" id="firstPageBtn" class="formBtn" value="第一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
			<input type="button" id="prePageBtn" class="formBtn" value="上一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
			第 <input type="text" id="currentPageText" class="formBtn" value="${currentPageNumber }" size="3" maxlength="4"/> / ${lastPageNumber} 頁
			<input type="button" id="nextPageBtn" class="formBtn" value="下一頁" <c:out value='${lastPageNumber<nextPageNumber ? "disabled": "" }'/> />
			<input type="button" id="lastPageBtn" class="formBtn" value="最末頁" <c:out value='${lastPageNumber<=currentPageNumber ? "disabled": "" }'/> />
		</div>
                <table id="queryResultTable">
				 <thead><tr>                       
                        <th><a id='a-sortHeader-uploadDate' href='javascript:void(0);' class="<c:out value='${uploadDateSortedClass }'/>"> <c:out value='${uploadDateSortedSpan }' escapeXml="false"/>上傳日期</a> </th>
                        <th>時間</th>
                        <th><a id='a-sortHeader-fileFormat' href='javascript:void(0);' class="<c:out value='${fileFormatSortedClass }'/>"> <c:out value='${fileFormatSortedSpan }' escapeXml="false"/>上傳類別</a></th>
                        <th><a id='a-sortHeader-fileName' href='javascript:void(0);' class="<c:out value='${fileNameSortedClass }'/>"> <c:out value='${fileNameSortedSpan }' escapeXml="false"/>檔案名稱</a></th>
                        <th><a id='a-sortHeader-uploadUser' href='javascript:void(0);' class="<c:out value='${uploadUserSortedClass }'/>"> <c:out value='${uploadUserSortedSpan }' escapeXml="false"/>上傳經辦</a></th>
                        <th>上傳結果</th>
                        <th>檢視內容</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${actionBean.queryResult.paginatedList}" var="viewObj" varStatus="rowstat">
                    <tr>                       
                        <td align="center"><fmt:formatDate value="${viewObj.uploadDate}" pattern="yyyy/MM/dd" /></td>
                        <td align="center"><fmt:formatDate value="${viewObj.uploadDate}" pattern="HH:mm:ss" /></td>
                        <td><c:out value="${viewObj.fileFormatName }" /></td>
                        <td><c:out value="${viewObj.fileName }" /> </td>
                        <td><c:out value="${viewObj.uploadUser.userName }" /></td>
                        <td><c:out value="${viewObj.fileStatusName }" /></td>
                        <td>
                        <div id="viewDetail-<c:out value='${viewObj.uploadFilePk}'/>" class="widgetsIcon ui-state-default ui-corner-all" title="檢視"><span class="ui-icon ui-icon-circle-triangle-e"></span></div>
                        </td>
                    </tr>
                    </c:forEach>
                    </tbody>
                    <tfoot>
                    <tr>
                        <td colspan="8" class="listFunction"><input type="button" value="列印" onclick="javascript:doPrintEvent();" class="formBtn"/></td>
                    </tr>
                    </tfoot>
                </table>
</c:if>
                
	</div>

<div style="display: none;">
<stripes:form id="hidden.queryUploadFileFrom" beanclass="com.feib.stms.action.Stms9003ActionBean" method="post" onsubmit="javascript: waitingDialog({});">
	<stripes:hidden id="hidden.qryUploaddDateFrom" name="qryUploaddDateFrom" formatPattern="yyyy/MM/dd"/>
	<stripes:hidden id="hidden.qryUploadDateHourFrom" name="qryUploadDateHourFrom" />
	<stripes:hidden id="hidden.qryUploadDateTo" name="qryUploadDateTo" formatPattern="yyyy/MM/dd" />
	<stripes:hidden id="hidden.qryUploadDateHourTo" name="qryUploadDateHourTo" />
	<stripes:hidden id="hidden.qryUploadUserId" name="qryUploadUserId" />	
	<c:forEach items="${actionBean.uploadFileFormats}" var="uploadFileFormatObj" varStatus="rowstat">
		<stripes:checkbox id="hidden.qryFileFormats[${rowstat.index}]" name="qryFileFormats[${rowstat.index}]" value="${uploadFileFormatObj.value}"/>
	</c:forEach>
	
	<stripes:hidden id="hidden.qryUploadFile.group.groupNo" name="qryUploadFile.group.groupNo" />
	<stripes:hidden id="hidden.qryUploadFile.group.groupPk" name="qryUploadFile.group.groupPk" />
		
	<stripes:hidden id="hidden.queryResult.pageNumber" name="queryResult.pageNumber" />
	<stripes:hidden id="hidden.queryResult.sortCriterion" name="queryResult.sortCriterion" />
	<stripes:hidden id="hidden.queryResult.sortDirection" name="queryResult.sortDirection" />
	<stripes:hidden id="hidden.qryUploadFilePk" name="qryUploadFilePk" />
	<stripes:submit id="hidden.doQueryBtn" name="doQuery" value="查詢" class="formBtn"/>
	<stripes:submit id="hidden.doViewDetailBtn" name="doViewDetail" value="明細" class="formBtn"/>
	<stripes:errors></stripes:errors>
</stripes:form>
</div>

</body>
</html>
